<?php


namespace app\admin\controller;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;

class text
{
    public function upload()
    {

//        $file = input('file');
        if (isset($_POST['sub'])) {
            $accessKey = config('qiniu.accessKey');     //AK值
            $secretKey = config('qiniu.secretKey');     //SK值
            $bucket = config('qiniu.bucket');     //空间名称
            $auth = new Auth($accessKey, $secretKey);
            $token = $auth->uploadToken($bucket); //获取token
            $filePath = $_FILES['file']['tmp_name'];       //获取上传的图片、文件
            $filename = date("YmdHis") . $_FILES["file"]["name"];        //自定义保存在七牛的文件名
            $uploadMgr = new UploadManager();       // 初始化 UploadManager 对象并进行文件的上传。
            list($ret, $err) = $uploadMgr->putFile($token, $filename, $filePath);
            if ($err !== null) {
                echo "成功";
                var_dump($err);
            } else {
                echo "失败";
                var_dump($ret);
            }
        }
    }
}